﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Auros.EPiSiteMap.Filters
{
    /// <summary>
    ///   Filters pages which do-not have public accress
    /// </summary>
    [SiteMapFilter]
    public class FilterPublicAccess : EPiServer.Filters.PageFilterBase
    {
        public override bool ShouldFilter(EPiServer.Core.PageData page)
        {
            var visitorPrinciple = new System.Security.Principal.GenericPrincipal(
                    new System.Security.Principal.GenericIdentity("visitor"),
                    new string[] { "Everyone" });

            return !page.ACL.QueryDistinctAccess(visitorPrinciple, EPiServer.Security.AccessLevel.Read);
        }
    }
}